﻿using System.Linq;
using Fuse8.ContentManagementFramework.Domain;
using Fuse8.DomainFramework.DataAccess.SqlDatabase;

namespace Fuse8.ContentManagementFramework.DataAccess
{
    public class CmsEntitySchemeBuilder : DefaultSqlSchemeBuilderForSuccessor
    {
        public override System.Collections.Generic.IList<DomainFramework.Domain.SqlColumn> GetColumns(System.Type type, System.Data.SqlClient.SqlConnection connection)
        {
            if (typeof(IContentItem).IsAssignableFrom(type))
            {
                var columns = new MsSqlSchemaBuilder().GetColumns(type, connection);
                var column = columns.FirstOrDefault(p => p.SqlColumnName == "Id");
                if (column != null)
                {
                    column.EntityPropertyName = "Id";
                    column.IsPrimaryKey = true;
                }

                return columns;
            }

            return null;
        }


    }
}